package com.example.anql.controller;

import com.example.anql.common.ReturnObject;
import com.example.anql.entity.OrderList;
import com.example.anql.service.OrderListService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (OrderList)表控制层
 *
 * @author makejava
 * @since 2022-12-10 12:46:13
 */
@RestController
@RequestMapping("/orderList")
public class OrderListController {
    /**
     * 服务对象
     */
    @Resource
    private OrderListService orderListService;



    /*
     *  查已下单 已发货 》0的
     * 为空则 查 >0 填数则正常where
     *
     * */

    @PostMapping("/list")
    public ReturnObject list(@RequestBody OrderList orderList) {

        return   orderListService.list(orderList);
    }


    /*
    * 账单管理 商品名称 商品id 成本  收入  利润
    *
    *
    * */

    @PostMapping("/orders")
    public Object orders() {

        return   orderListService.orders();
    }
    /**
     * 分页查询
     *
     * @param orderList 筛选条件
     * @return 查询结果
     */
    @PostMapping("/queryByPage")
    public ReturnObject queryByPage(@RequestBody OrderList orderList ) {

        return   orderListService.queryByPage(orderList);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("/queryById")
    public ResponseEntity<OrderList> queryById(@RequestBody OrderList orderList ) {
        return ResponseEntity.ok(this.orderListService.queryById(orderList.getId()));
    }

    /**
     * 新增数据
     *
     * @param orderList 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResponseEntity<OrderList> add(@RequestBody OrderList orderList) {
        return ResponseEntity.ok(this.orderListService.insert(orderList));
    }

    /**
     * 编辑数据
     *
     * @param orderList 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public ResponseEntity<OrderList> edit(@RequestBody OrderList orderList) {
        return ResponseEntity.ok(this.orderListService.update(orderList));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/deleteById")
    public ResponseEntity<Boolean> deleteById(@RequestBody OrderList orderList) {
        return ResponseEntity.ok(this.orderListService.deleteById(orderList.getId()));
    }

}

